﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;
namespace Ebada.Modules.Document
{
    /// <summary>
    /// 库位选择器
    /// </summary>
    public partial class frmDocumentPositionSeletr : FormBase
    {
       
       
        public frmDocumentPositionSeletr() 
        {
            InitializeComponent();
        }
        public DocumentPosition D_Position = new DocumentPosition();
        private void frmDocumentPositionSeletr_Load(object sender, EventArgs e)
        {
            IList<DocumentPosition> dp_list = MainHelper.PlatformSqlMap.GetList<DocumentPosition>("where 2>1 and Org_ID='" + MainHelper.UserBaseX.Org_ID + "'order by Org_ID");
            treeList1.DataSource = dp_list;
            Init_Org();
        }
        /// <summary>
        /// 根据sqlwhere条件筛选数据
        /// </summary>
        /// <param name="sqlwhere"></param>
        public void RefreshData(string sqlwhere)
        {
            IList<DocumentPosition> dp_list = MainHelper.PlatformSqlMap.GetList<DocumentPosition>(sqlwhere);
            treeList1.DataSource = dp_list;
        }
       /// <summary>
       /// 设置指定单位库位获得焦点
       /// </summary>
       /// <param name="Org_ID">单位ID</param>
        public void SetFocus(string Org_ID)
        {
            for (int i = 0; i < treeList1.Nodes.Count; i++)
            {
                if (treeList1.Nodes[i].GetValue("Org_ID").ToString()==Org_ID)
                {
                    treeList1.Nodes[i].Selected = true;
                    break;
                }
            }
        }
        public void Init_Org()
        {
            DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit comboBox = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
            treeList1.Columns["Org_ID"].ColumnEdit = comboBox;
            IList<mOrg> org_list = MainHelper.PlatformSqlMap.GetList<mOrg>("");
            comboBox.DataSource = org_list;
            comboBox.DisplayMember = "cnName";
            comboBox.ValueMember = "Org_ID";

        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            D_Position.DocumentPositionID = e.Node["DocumentPositionID"].ToString();
            D_Position.ParentID = e.Node["ParentID"].ToString();
            D_Position.PositionLevel = Convert.ToInt32(e.Node["PositionLevel"].ToString());
            D_Position.PositionName = e.Node["PositionName"].ToString();
            D_Position.Org_ID = e.Node["Org_ID"].ToString();
        }

        private void treeList1_DoubleClick(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
       
       
    }
}